package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SupplierManagement;
import com.ruoyi.system.service.ISupplierManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 供应商信息管理Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/management")
public class SupplierManagementController extends BaseController {
    @Autowired
    private ISupplierManagementService supplierManagementService;

    /**
     * 查询供应商信息管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplierManagement supplierManagement) {
        startPage();
        List<SupplierManagement> list = supplierManagementService.selectSupplierManagementList(supplierManagement);
        return getDataTable(list);
    }

    /**
     * 查询供应商信息管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:management:list')")
    @GetMapping("/xialaxuan")
    public AjaxResult xialaxuan(SupplierManagement supplierManagement) {
        startPage();
        List<SupplierManagement> list = supplierManagementService.selectSupplierManagementList(supplierManagement);
        return AjaxResult.success(list);
    }

    /**
     * 导出供应商信息管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:management:export')")
    //@Log(title= "供应商信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplierManagement supplierManagement) {
        List<SupplierManagement> list = supplierManagementService.selectSupplierManagementList(supplierManagement);
        ExcelUtil<SupplierManagement> util = new ExcelUtil<SupplierManagement>(SupplierManagement.class);
        util.exportExcel(response, list, "供应商信息管理数据");
    }

    /**
     * 获取供应商信息管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable("supplierId") String supplierId) {
        return success(supplierManagementService.selectSupplierManagementBySupplierId(supplierId));
    }

    /**
     * 新增供应商信息管理
     */
    //@PreAuthorize("@ss.hasPermi('system:management:add')")
    //@Log(title= "供应商信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplierManagement supplierManagement) {
        return toAjax(supplierManagementService.insertSupplierManagement(supplierManagement));
    }

    /**
     * 修改供应商信息管理
     */
    //@PreAuthorize("@ss.hasPermi('system:management:edit')")
    //@Log(title= "供应商信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplierManagement supplierManagement) {
        return toAjax(supplierManagementService.updateSupplierManagement(supplierManagement));
    }

    /**
     * 删除供应商信息管理
     */
    //@PreAuthorize("@ss.hasPermi('system:management:remove')")
    //@Log(title= "供应商信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable String[] supplierIds) {
        return toAjax(supplierManagementService.deleteSupplierManagementBySupplierIds(supplierIds));
    }
}
